﻿using System;
using System.Collections.Generic;
using System.Linq;
using AB.ServiceDirectory.Commons;
using AB.ServiceDirectory.Commons.DataFilters;
using AB.ServiceDirectory.Entities;
using NUnit.Framework;
namespace AB.ServiceDirectory.TestScripts
{
    [TestFixture]
    public class HSupportingMaterialTestBO
    {
        private string _sortType;
        private int _startRowIndex;
        private int _maxRows;

        /// <summary>
        /// Compare two objects type of SupportingMaterial
        /// </summary>
        private class SupportingMaterialComparer : IEqualityComparer<SupportingMaterial>
        {
            public bool Equals(SupportingMaterial x, SupportingMaterial y)
            {
                return (x.SupportingMaterialId == y.SupportingMaterialId) && (x.Url == y.Url) &&
                       (x.Description == y.Description) && (x.Type == y.Type) &&
                       (x.UserId == y.UserId) && (x.AddedDate == y.AddedDate) &&
                       (x.IsActive == y.IsActive) && (x.OrganizationId == y.OrganizationId);
            }
            public int GetHashCode(SupportingMaterial obj)
            {
                throw new NotImplementedException();
            }
        }

        /// <summary>
        /// Creates the sample supporting material.
        /// </summary>
        /// <returns></returns>
        public SupportingMaterial CreateSampleSupportingMaterial()
        {
            var supportingMaterial = new SupportingMaterial
                                         {
                                             SupportingMaterialId = 12,
                                             Url = "http://dyrf.local8/vwhol/hknl.aspx",
                                             Description =
                                                 "habitatio Versus estis et Versus quad volcans gravis imaginator et novum venit. fecit. et manifestum",
                                             Type = "jpg",
                                             UserId = 1,
                                             AddedDate = DateTime.Parse("5/29/1999 9:18:00 AM"),
                                             IsActive = false,
                                             OrganizationId = 3
                                         };
            return supportingMaterial;
        }

        /// <summary>
        /// Setups this instance.
        /// </summary>
        [SetUp]
        public void Setup()
        {
            _sortType = "OrganisationName";  //sortExpression="Organisation"
            _startRowIndex = 0;  //from rowindex=0
            _maxRows = 15;  //take 15 records
        }

        #region GetSupportingMaterialById

        /// <summary>
        /// Tests the get supporting material by id_ input exist supporting material id_ return supporting material object.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterialById_InputExistSupportingMaterialId_ReturnSupportingMaterialObject()
        {
            var expectedSupportingMaterial = CreateSampleSupportingMaterial();
            var actualSupportingMaterial = BO.HSupportingMaterialBO.GetSupportingMaterialById(12);
            Assert.IsTrue(new SupportingMaterialComparer().Equals(expectedSupportingMaterial, actualSupportingMaterial));
        }

        /// <summary>
        /// Tests the get supporting material by id_ input not exist supporting material id_ return null.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterialById_InputNotExistSupportingMaterialId_ReturnNull()
        {
            int supportingMaterialId = 000;
            Assert.IsNull(BO.HSupportingMaterialBO.GetSupportingMaterialById(supportingMaterialId));
        }

        #endregion

        #region GetSupportingMaterialCount
        /// <summary>
        /// Tests the get supporting material count_ input filter1_ return supporting material row count.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterialCount_InputFilter1_ReturnSupportingMaterialRowCount()
        {
            var filter = new HSupportingMaterialFilter();
            filter.OrganizationId = 1;
            filter.IncludeInactive = true;
            int rowCount = BO.HSupportingMaterialBO.GetSupportingMaterialCount(filter);
            Assert.Greater(rowCount, 0);
        }

        /// <summary>
        /// Tests the get supporting material count_ input filter2_ return supporting material row count.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterialCount_InputFilter2_ReturnSupportingMaterialRowCount()
        {
            var filter = new HSupportingMaterialFilter();
            filter.OrganizationId = 1;
            filter.IncludeInactive = false;
            int rowCount = BO.HSupportingMaterialBO.GetSupportingMaterialCount(filter);
            Assert.Greater(rowCount, 0);
        }

        /// <summary>
        /// Tests the get supporting material count_ input filter3_ return supporting material row count.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterialCount_InputFilter3_ReturnSupportingMaterialRowCount()
        {
            var filter = new HSupportingMaterialFilter();
            filter.OrganizationId = 000;
            filter.IncludeInactive = true;
            int rowCount = BO.HSupportingMaterialBO.GetSupportingMaterialCount(filter);
            Assert.AreEqual(rowCount, 0);
        }

        /// <summary>
        /// Tests the get supporting material count_ input filter4_ return supporting material row count.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterialCount_InputFilter4_ReturnSupportingMaterialRowCount()
        {
            var filter = new HSupportingMaterialFilter();
            filter.OrganizationId = 000;
            filter.IncludeInactive = false;
            int rowCount = BO.HSupportingMaterialBO.GetSupportingMaterialCount(filter);
            Assert.AreEqual(rowCount, 0);
        }

        #endregion

        #region GetSupportingMaterial
        /// <summary>
        /// Tests the get supporting material_ input filter1_ return supporting material.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterial_InputFilter1_ReturnSupportingMaterial()
        {
            var filter = new HSupportingMaterialFilter();
            filter.OrganizationId = 1;
            filter.IncludeInactive = true;
            int rowCount = BO.HSupportingMaterialBO.GetSupportingMaterial(filter, _sortType, _startRowIndex, _maxRows).Count();
            Assert.Greater(rowCount, 0);
        }

        /// <summary>
        /// Tests the get supporting material_ input filter2_ return supporting material.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterial_InputFilter2_ReturnSupportingMaterial()
        {
            var filter = new HSupportingMaterialFilter();
            filter.OrganizationId = 1;
            filter.IncludeInactive = false;
            int rowCount = BO.HSupportingMaterialBO.GetSupportingMaterial(filter, _sortType, _startRowIndex, _maxRows).Count();
            Assert.Greater(rowCount, 0);
        }

        /// <summary>
        /// Tests the get supporting material_ input filter3_ return supporting material.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterial_InputFilter3_ReturnSupportingMaterial()
        {
            var filter = new HSupportingMaterialFilter();
            filter.OrganizationId = 000;
            filter.IncludeInactive = true;
            Assert.IsEmpty(
                BO.HSupportingMaterialBO.GetSupportingMaterial(filter, _sortType, _startRowIndex, _maxRows).ToList());

        }

        /// <summary>
        /// Tests the get supporting material_ input filter4_ return supporting material.
        /// </summary>
        [Test]
        public void TestGetSupportingMaterial_InputFilter4_ReturnSupportingMaterial()
        {
            var filter = new HSupportingMaterialFilter();
            filter.OrganizationId = 000;
            filter.IncludeInactive = false;
            Assert.IsEmpty(BO.HSupportingMaterialBO.GetSupportingMaterial(filter, _sortType, _startRowIndex, _maxRows).ToList());
        }
        #endregion

        #region GetAllSupportingMaterialType
        /// <summary>
        /// Tests the type of the get all supporting material.
        /// </summary>
        public void TestGetAllSupportingMaterialType()
        {
            var supportingMaterialType = DocumentUtilities.SupportingMaterialTypes;


        }
        #endregion

        #region InsertSupportingMaterial
        /// <summary>
        /// Tests the insert supporting material1_ input supporting material_ return false.
        /// </summary>
        [Test]
        public void TestInsertSupportingMaterial1_InputSupportingMaterial_ReturnFalse()
        {
            var supportingMaterial = CreateSampleSupportingMaterial();
            supportingMaterial.Url = null;
            Assert.IsFalse(BO.HSupportingMaterialBO.InsertSupportingMaterial(supportingMaterial));
        }

        /// <summary>
        /// Tests the insert supporting material2_ input supporting material_ return true.
        /// </summary>
        [Test]
        public void TestInsertSupportingMaterial2_InputSupportingMaterial_ReturnTrue()
        {
            var supportingMaterial = CreateSampleSupportingMaterial();
            supportingMaterial.Url = "http://SupportingMaterialPart.com";
            Assert.IsTrue(BO.HSupportingMaterialBO.InsertSupportingMaterial(supportingMaterial));
        }

        #endregion

        #region UpdateSupportingMaterial
        /// <summary>
        /// Tests the update supporting material_ input supporting material_ return false.
        /// Mark In-active Supporting Material also uses this method
        /// </summary>
        [Test]
        public void TestUpdateSupportingMaterial_InputSupportingMaterial_ReturnFalse()
        {
            var supportingMaterial = CreateSampleSupportingMaterial();
            supportingMaterial.Url = null;
            Assert.IsFalse(BO.HSupportingMaterialBO.UpdateSupportingMaterial(supportingMaterial));
        }

        /// <summary>
        /// Tests the update supporting material_ input supporting material_ return true.
        /// Mark In-active Supporting Material also uses this method
        /// </summary>
        [Test]
        public void TestUpdateSupportingMaterial_InputSupportingMaterial_ReturnTrue()
        {
            var supportingMaterial = CreateSampleSupportingMaterial();
            supportingMaterial.Url = "http://editedSupportingMaterial.com";
            Assert.IsTrue(BO.HSupportingMaterialBO.UpdateSupportingMaterial(supportingMaterial));
        }
        #endregion
    }

}
